package leetcode.code0899;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;

import leetcode.IDebug;
import leetcode.helper.H;

//执行用时：2 ms, 在所有 Java 提交中击败了93.84%的用户
//
//内存消耗：41.5 MB, 在所有 Java 提交中击败了44.55%的用户
//
//通过测试用例：110 / 110
public class Solution implements IDebug {

	public String orderlyQueue(String s, int k) {
		if (k == 1) {
			String ans = s;
			StringBuffer sb = new StringBuffer(s);
			for (int i = 0; i < s.length(); i++) {
				sb.append(sb.charAt(0)).deleteCharAt(0);
				if (sb.toString().compareTo(ans) < 0) {
					ans = sb.toString();
				}
			}
			return ans;
		} else {
			char[] cs = s.toCharArray();
			Arrays.sort(cs);
			return new String(cs);
		}
	}

	@Override
	public void debug4() {
		H.compare("cikk", this.orderlyQueue("kikc", 3));
		H.compare("aakrsv", this.orderlyQueue("askvra", 6));
		H.compare("hku", this.orderlyQueue("kuh", 1));
		H.compare("aaabc", this.orderlyQueue("baaca", 3));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
